package com.itcast.demo11;

import java.util.*;

public class Demo02 {
    public static void main(String[] args) {
        /*
        * public class CollectionDemo {

    public static void main(String[] args) {


        //提供一个方法，能够完成将该学生集合 按照生日进行倒叙排列的操作，并打印查看

        //提供一个方法完成如下功能
        // 去重：同学座位有重复的情况，只保留唯一一个，条件是，谁生日大谁留下（原有集合10，重复5个，最终剩下5个）
        //打印的时候顺序不需要保证


    }
}*/
        List<Student> studentList = new ArrayList<>();

        Calendar calendar = Calendar.getInstance();
        Student stu = null;
        for (int i = 0; i < 10 ; i++) {
            int month = new Random().nextInt(12);
            int day = new Random().nextInt(28);
            int local = new Random().nextInt(5);
            calendar.set(2020,month,day);
            Date birthday = calendar.getTime();
            stu = new Student(i,"同学座位"+local,birthday);
            studentList.add(stu);
            studentList.add(stu);
            studentList.add(stu);
            studentList.add(stu);
            studentList.add(stu);

        }
     //  mehtod(studentList);

//        for (int i=0;i<20;i++) {

//        }
       method2(studentList);
    }
    public static void mehtod( List<Student> list){
     TreeSet<Student> set = new TreeSet<>();
        for (int i = 0; i < list.size(); i++) {
            set.add(list.get(i));
        }
        System.out.println(set);
    }

    public  static void method2( List<Student> list){
        for (int i = 0; i<list.size(); i++) {
            for (int i1 = list.size()-1; i1 >i; i1--) {
                if(list.get(i).getZuo().equals(list.get(i1).getZuo())&&(list.get(i)!=list.get(i1))){
                    if(list.get(i).getBrithday().compareTo(list.get(i1).getBrithday())<0){
                      list.remove(i1);
                    }
                }
            }
        }
        System.out.println("==========");
        System.out.println(list.size());
    }
}
